<?php
class SP_Path
{
	protected static $paths=array();
	protected static $include;
	
	public static function getInstance()
	{
        static $instance;
        if (!isset($instance))
		{
            $cl = __CLASS__;
            $instance = new $cl();
        }
        return $instance;
    }
	
	public static function set($name,$value, $to=null)
	{
		if( $to ) $to=self::get($to, false);
		self::$paths[$name]=$to.$value;
	}
	
	public static function has($name)
	{
		return array_key_exists($name, self::$paths);
	}
	
	public static function setInclude($value)
	{
		self::$include=$value;
	}
	
	public static function getInclude()
	{
		return self::$include.'/';
	}
	
	public static function get($name, $full=true)
	{
		if( self::has($name) )
		{
			if( $full ) $out=self::getInclude();
			if( substr(self::$paths[$name], -4)=='.php' or substr(self::$paths[$name], -1)=='/')
			{
				$out.=self::$paths[$name];
			}
			else
			{
				$out.=self::$paths[$name].'/';
			}
			return $out;
		}
	}
	
	public static function isFile($path, $name=null)
	{
		if( $name )
		{
			return is_file(self::get($name).$path);
		}
		else
		{
			return is_file($path);
		}
	}
	
	public static function remove($name)
	{
		unset(self::$paths[$name]);
	}
	
	public function getAll()
	{
		return self::$paths;
	}
	
	public function clear()
	{
		self::$paths=array();
	}
}
